地学数据三维可视化-工具
¶



汪宇锋
地球物理与空间信息学院
2021年11月

信息可视化和科学可视化¶


  • 信息可视化(InfoVis) visualizes arbitrary and potentially abstract types of information, typically in 2D or 2D+time plots with axes and numerical scales.

  • 科学可视化(SciVis) focus on visualizing physically situated gridded data in 3D and 3D+time, often without spatial axes and instead providing an immersive visual experience of real-world physical datasets (see Weiskopf et al for a comparison).

  • Desktop-GUI targeted SciVis tools build on the OpenGL graphics standard, while browser-based web applications usually leverage the related WebGL graphics standard.

信息可视化和科学可视化¶

(Credit by Jake VanderPlas and Nicolas Rougier "Python’s Visualization Landscape")

Matplotlib¶


Common Idea: Keep matplotlib as a versatile, well-tested backend, and provide a new domain-specific API.

In [1]:
# Import seaborn
import seaborn as sns
import pandas as pd

# Apply the default theme
sns.set_theme()

# Load an example dataset
# tips = sns.load_dataset("tips")

df = pd.read_csv("./data/tips.csv")
if df.iloc[-1].isnull().all():
    df = df.iloc[:-1]

df["day"] = pd.Categorical(df["day"], ["Thur", "Fri", "Sat", "Sun"])
df["sex"] = pd.Categorical(df["sex"], ["Male", "Female"])
df["time"] = pd.Categorical(df["time"], ["Lunch", "Dinner"])
df["smoker"] = pd.Categorical(df["smoker"], ["Yes", "No"])
In [2]:
# Create a visualization
sns.relplot(
    data=df,
    x="total_bill", y="tip", col="time",
    hue="smoker", style="smoker", size="size",
)
Out[2]:
<seaborn.axisgrid.FacetGrid at 0x110b8fca0>
In [3]:
sns.displot(data=df, x="total_bill", col="time", kde=True)
Out[3]:
<seaborn.axisgrid.FacetGrid at 0x1262772e0>
In [4]:
df = pd.read_csv("./data/penguins.csv")
if df.iloc[-1].isnull().all():
    df = df.iloc[:-1]
df["sex"] = df["sex"].str.title()
sns.jointplot(data=df, x="flipper_length_mm", y="bill_length_mm", hue="species")
Out[4]:
<seaborn.axisgrid.JointGrid at 0x1260728b0>

信息可视化工具-Matplotlib¶

  • Strengths:
    • Designed like MatLab: switching was easy
    • Many rendering backends
    • Can reproduce just about any plot with a bit of effort
    • Well-tested, standard tool for over a decade
  • Weaknesses:
    • API is imperative & often overly verbose
    • Sometimes poor stylistic defaults
    • Poor support for web/interactive graphs
    • Often slow for large & complicated data
In [5]:
sns.pairplot(data=df, hue="species")
Out[5]:
<seaborn.axisgrid.PairGrid at 0x126a007c0>

信息可视化工具-Javascript¶


Common Idea: build a new API that produces a plot serialization (often JSON) that can be displayed in the browser (often in Jupyter notebooks).

信息可视化工具-ipywidgets¶



(Credit by Martin Renou, "Video streaming in the Jupyter Notebook")

In [6]:
import ipyvolume
ds = ipyvolume.datasets.aquariusA2.fetch()
ipyvolume.quickvolshow(ds.data, lighting=True)
/Users/wangyufeng/opt/anaconda3/lib/python3.8/site-packages/ipyvolume/serialize.py:92: RuntimeWarning: invalid value encountered in true_divide
  gradient = gradient / np.sqrt(gradient[0] ** 2 + gradient[1] ** 2 + gradient[2] ** 2)

信息可视化工具-Bokeh¶

  • Strengths:
    • Web view/interactivity
    • Imperative and Declarative layer
    • Handles large and/or streaming datasets
    • Geographical visualization
    • Fully open source
  • Weaknesses:
    • No vector output
    • Newer tool with a smaller user-base than matplotlib

信息可视化工具-Plotly¶

  • Strengths:
    • Web view/interactivity
    • Multi-language support
    • 3D plotting capability
    • Animation capability
    • Geographical visualization
  • Weaknesses:
    • Some features require a paid plan

Bokeh vs. Plotly¶


  • Use in Jupyter / iPython / scripts
    • both frameworks do a good job for this use case.
  • Use as a dashboard
    • both frameworks are based on a producer-consumer architecture communicating over JSON
    • Bokeh tends to have more layers of abstraction than Plotly
    • both frameworks integrate with an existing Python-based web server

(Credit by Paul Iacomi "Plotly vs. Bokeh: Interactive Python Visualisation Pros and Cons")

In [7]:
from bokeh.plotting import figure, output_notebook, show
output_notebook() # needs to be called to output in the notebook

# prepare some data
x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
y = [i**2 for i in x]

# create a new plot
fig = figure(
    tools="pan,box_zoom,wheel_zoom,zoom_in,zoom_out,reset,save",
    title="Example Bokeh plot",
    y_axis_type="log",
    y_range=[0.001, 10**3],
    x_axis_label='Sections',
    y_axis_label='Particles (log)',
    plot_width=600, plot_height=400,
)

# plot some data ('renderers' in Bokeh)
fig.circle(x, x, legend_label="y=x", fill_color="white", size=8)
fig.line(x, y, legend_label="y=x^2", line_width=3, line_color="red")
Loading BokehJS ...
Out[7]:
GlyphRenderer(
id = '1058', …)
data_source = ColumnDataSource(id='1055', ...),
glyph = Line(id='1056', ...),
hover_glyph = None,
js_event_callbacks = {},
js_property_callbacks = {},
level = 'glyph',
muted = False,
muted_glyph = None,
name = None,
nonselection_glyph = Line(id='1057', ...),
selection_glyph = 'auto',
subscribed_events = [],
syncable = True,
tags = [],
view = CDSView(id='1059', ...),
visible = True,
x_range_name = 'default',
y_range_name = 'default')
In [8]:
# show the results
show(fig)
In [9]:
import plotly.graph_objects as go

# prepare some data
x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
y = [i**2 for i in x]

# create a new plot
fig = go.Figure(
    layout=dict(
        title="Example Plotly plot",
        yaxis_type="log",
        yaxis_range=[-3, 3],  # Plotly takes ranges differently!
        xaxis_title='sections',
        yaxis_title='particles',
    )
)
In [10]:
# show the results
# plot some data ('traces' in Plotly)
fig.add_trace(go.Scatter(x=x, y=x, mode='markers', name="y=x", marker=dict(color='royalblue', size=8)))
fig.add_trace(go.Scatter(x=x, y=y, name="y=x^2", line=dict(width=3)))
fig.show()

科学可视化工具-Kitware¶


  • The Visualization Toolkit - VTK (from Kitware) supports manipulating and displaying scientific data by enabling 3D rendering, widgets for 3D interaction, and 2D plotting capability.

  • ParaView (from Kitware) is an application built on the Visualization Toolkit (VTK) with extensions for distributed computing. ParaView allows users to quickly build visualizations to analyze their data using qualitative and quantitative techniques. The data exploration can be done interactively in 3D or programmatically using batch processing capabilities.

科学可视化工具-Enthought¶


  • Mayavi (from Enthought) is a general purpose, cross-platform tool for 3-D scientific data visualization.

科学可视化工具-OpenGL¶


  • VisPy is a high-performance interactive 2D/3D data visualization library leveraging the computational power of modern Graphics Processing Units (GPUs) through the OpenGL library to display very large datasets.

  • Glumpy is an OpenGL-based interactive visualization library in Python. Its goal is to make it easy to create fast, scalable, beautiful, interactive and dynamic visualizations.

科学可视化工具-VTK¶

  • PyVista is a streamlined interface for the Visualization Toolkit (VTK) providing 3D plotting and mesh analysis with NumPy support being at its core.

  • vedo is a lightweight module for scientific analysis and visualization of polygonal meshes, point clouds and volumetric data. It offers an intuitive API which can be combined with VTK seamlessly in a program.

  • itk-jupyter-widgets, based on the Visualization Toolkit for JavaScript vtk.js and the Insight Toolkit (ITK), provides interactive 3D widgets for Jupyter to visualize and analyze images, point sets, and meshes.

In [1]:
import pyvista as pv
from pyvista import examples
import numpy as np
import rasterio

topo = pv.read('./fig/topo_clean.vtk')
filename = './fig/Geologic_map_on_air_photo.tif'
texture = pv.read_texture(filename)

def get_gcps(filename):
    """This helper function retrieves the Ground Control
    Points of a GeoTIFF. Note that this requires gdal"""
    get_point = lambda gcp: np.array([gcp.x, gcp.y, gcp.z])
    # Load a raster
    src = rasterio.open(filename)
    # Grab the Groung Control Points
    points = np.array([get_point(gcp) for gcp in src.gcps[0]])
    # Now Grab the three corners of their bounding box
    # -- This guarantees we grab the right points
    bounds = pv.PolyData(points).bounds
    origin = [bounds[0], bounds[2], bounds[4]]  # BOTTOM LEFT CORNER
    point_u = [bounds[1], bounds[2], bounds[4]]  # BOTTOM RIGHT CORNER
    point_v = [bounds[0], bounds[3], bounds[4]]  # TOP LEFT CORNER
    return origin, point_u, point_v


# Fetch the GCPs
origin, point_u, point_v = get_gcps(filename)
# Use the GCPs to map the texture coordiantes onto the topography surface
topo.texture_map_to_plane(origin, point_u, point_v, inplace=True)

# Show GCPs in relation to topo surface with texture coordinates displayed
p = pv.Plotter()
p.add_point_labels(
    np.array(
        [
            origin,
            point_u,
            point_v,
        ]
    ),
    ["Origin", "Point U", "Point V"],
    point_size=5,
)

p.add_mesh(topo)

# Now plot the topo surface with the texture draped over it
# And make window size large for a high-res screenshot
p = pv.Plotter(window_size=np.array([1024, 768]) * 3)
p.add_mesh(topo, texture=texture)
p.camera_position = [
    (337461.4124956896, 4257141.430658634, 2738.4956020899253),
    (339000.40935731295, 4260394.940646875, 1724.0720826501868),
    (0.10526647627366331, 0.2502863297360612, 0.962432190920575),
]
In [2]:
p.show()

科学可视化工具¶


  • GR is a universal framework for cross-platform visualization applications. It offers developers a compact, portable and consistent graphics library for their programs.

  • yt is a package for analyzing and visualizing volumetric data. yt supports structured, variable-resolution meshes, unstructured meshes, and discrete or sampled data such as particles.

Communities¶

  • PyViz is an open platform for helping users decide on the best open-source (OSS) Python data visualization tools for their purposes, with links, overviews, comparisons, and examples.

  • HoloViz uses a wide range of open-source Python libraries, but focusing on the tools we help maintain as part of the HoloViz project: Panel, hvPlot, HoloViews, GeoViews, Datashader, Param, and Colorcet.

Conferences¶

  • IEEEvis is the year’s premier forum for advances in theory, methods, and applications of visualization and visual analytics.

  • SciVis Contest 2021: Earth’s Mantle Convection.

In [10]:
from IPython.display import HTML
HTML('<iframe src="https://player.vimeo.com/video/459406913?h=1613ccc704" width="640" height="426" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe><p><a href="https://vimeo.com/459406913">Earth&#039;s mantle convection</a> from <a href="https://vimeo.com/computecanada">Compute Canada</a> on <a href="https://vimeo.com">Vimeo</a>.</p>')
Out[10]:

Earth's mantle convection from Compute Canada on Vimeo.

Conferences¶

  • 中国可视化与可视分析大会 (ChinaVis) 由我国可视化业界工作者联合发起,宗旨是促进中国及周边地区的可视化与可视分析研究与应用的交流,探讨在大数据时代可视化与可视分析发展的方向与机遇,推动相关研究与应用的发展与进步,推进学科的发展,促进人才培养和交流,加深艺术与技术融合。

Companies¶

  • blender Blender's mission is to bring the best 3D technology as tools in the hands of artists, for all platforms, everywhere in the world, free and open source forever.

  • Bentley's Infrastructure Digital Twins Connect the Physical and Virtual World Synchronize work, gain greater visibility, and make sense of the right data at the right time across the lifecycle of assets.

  • Mira Geoscience has pioneered the application of advanced geological modelling, 3D-GIS technology, and 4D multi-disciplinary data management in the mining industry through the integrated “Common Earth Model”.

下节课预告¶